home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / qtawk / filename.exp < prev    next >
Text File  |  1990-04-23  |  1KB  |  31 lines

  1. # QTAwk utility to split input lines into DOS path and filename.ext
  2. #
  3. BEGIN {
  4.     # characters excluded from filename
  5.     # all other characters are valid filename characters for DOS
  6.     exc_c = /[!\x01-\x21."\/\\\[\]:|<>+=;,]/;
  7.     # DOS filename.ext pattern
  8.     # filename consists of all characters not excluded from proper name
  9.     # followed by optional extension of 1 to 3 characters
  10.     # followed by end of string
  11.     name_pat = /{exc_c}+(\.{exc_c}{1,3})?$/;
  12. }
  13.  
  14. # split each line into "path" and "filename"
  15. # strategy: delete "filename.ext" from end using regular expression
  16. #   to recognize and "sub" function to replace with zero length string.
  17. #   use "substr" function to then get suffix of path, which is the
  18. #   filename.ext. This strategy works even if filename.ext is not present.
  19. #
  20.     {
  21.     # everything into path
  22.     path = $0;
  23.     # delete filename.ext at end to leave path
  24.     sub(name_pat,"",path);
  25.     # get suffix of path, which is filename.ext
  26.     filename = substr($0,1 + length(path));
  27.  
  28.     print path;
  29.     print filename;
  30. }
  31.